home *** CD-ROM | disk | FTP | other *** search
- /*
- CDSearch - An XFCN to Search absolute minute, second, block
- ©Apple Computer, Inc. 1988
- All Rights Reserved.
-
- 88/10/08 BL°B First Version
-
- To compile and link this file using Macintosh Programmer's Workshop,
-
- C -q2 CDSearch.c
- link -sn Main=CDSearch -sn STDIO=CDSearch ∂
- -sn INTENV=CDSearch -rt XFCN=42 ∂
- -m CDSearch CDSearch.c.o "{CLibraries}"CRuntime.o ∂
- "{CLibraries}"StdCLib.o ∂
- -o HyperCommands
-
- This link directive puts the XCMD in the file "HyperCommands".
- Substitute the name of the stack you want it in. To move XCMDs
- between stacks, use ResEdit. They can be in an individual stack,
- the Home stack, the HyperCard application, or the System File.
-
- */
-
- #include <cd.h>
-
- /* prototype definitions for functions */
- void ExtractBCD(char *, short *);
- OSErr ASearch(XCmdBlockPtr, short, short, short, short, short);
-
- /* **** WARNING: DO NOT USE GLOBAL VARIABLES! **** */
-
-
- /************************************************************************
- *
- * Function: CDSearch
- *
- * Purpose: Search absolute minute, second and block
- *
- * Returns: result of driver call to Search
- * normally 0, but could have parameter error or
- * other error if non-existent block is specified
- *
- * Side Effects:
- *
- * Description: We need four parameters:
- * 1) a flag indicating whether to play or pause at
- * this address
- * 2) the minute
- * 3) the second
- * 4) the block
- * Get the ioRefNum by accessing the famous global
- * set in CDOpen().
- * Extract the minute, second and block and start
- * Searching at that point.
- *
- ************************************************************************/
- pascal void
- CDSearch(paramPtr)
- XCmdBlockPtr paramPtr;
- {
- Str31 returnString;
- OSErr result;
- short minute;
- short second;
- short block;
- short ioRefNum;
- Handle refHandle;
- short flag;
-
- /* Must be four parameters */
- if ((paramPtr->paramCount) != 4)
- {
- /* Report error in parameters by returning -1 */
- NumToStr(paramPtr, (long) -1, &returnString);
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
- return;
- }
-
- /* Get the global ioRefNum and convert it. */
- refHandle = GetGlobal(paramPtr, GLOBALNAME);
- ioRefNum = atoi(*(refHandle));
- DisposHandle(refHandle);
- ioRefNum &= 0xFFFF; /* remove vRefNum; not needed. */
-
- /* First param is flag. Convert it to a short */
- flag = atoi(*(paramPtr->params[0]));
-
- /* Second param is minute. Convert it to a pascal string */
- ExtractBCD((char *)*(paramPtr->params[1]), &minute);
-
- /* Third param is second. Convert it to a pascal string */
- ExtractBCD((char *)*(paramPtr->params[2]), &second);
-
- /* Fourth param is block. Convert it to a pascal string */
- ExtractBCD((char *)*(paramPtr->params[3]), &block);
-
- result = ASearch(paramPtr, ioRefNum, flag, minute, second, block);
-
- /* Convert result to string & return it */
- NumToStr(paramPtr, (long) result, &returnString);
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
- }
-
- /************************************************************************
- *
- * Function: ExtractBCD
- *
- * Purpose: Extract number in BCD from PString
- *
- * Returns: nothing
- *
- * Side Effects: *track gets a new value
- *
- * Description: Extract number in BCD from Cstring "name".
- * "name" is always of the form "XX", where XX
- * ranges from "1" to "99"
- *
- ************************************************************************/
- void
- ExtractBCD(name, number)
- char *name;
- short *number;
- {
- short t;
-
- t = 0;
- while (*name != 0)
- {
- t *= 16;
- t += *name - '0';
- name++;
- }
-
- *number = t;
- }
-
- /************************************************************************
- *
- * Function: ASearch
- *
- * Purpose: start Searching at an absolute minute, second, block
- *
- * Returns: OSErr. Probably either
- * noErr everything's hunky-dory!
- * paramErr you messed up the call somehow.
- *
- * Side Effects: starts Search. By default, this will Search until the
- * end of the disc.
- *
- * Description: pass in the absolute minute, second and block in BCD.
- *
- ************************************************************************/
- OSErr
- ASearch(paramPtr, refNum, flag, minute, second, block)
- XCmdBlockPtr paramPtr;
- short refNum;
- short flag;
- short minute;
- short second;
- short block;
- {
- CDParam myPB;
- short playMode;
- Handle refHandle;
-
- /* Get the global ioRefNum and convert it. */
- refHandle = GetGlobal(paramPtr, PLAYMODE);
- playMode = atoi(*(refHandle));
- DisposHandle(refHandle);
-
- myPB.ioCompletion = 0;
- myPB.ioNamePtr = (char *) 0;
- myPB.ioVRefNum = 1;
- myPB.ioCRefNum = refNum;
- myPB.csCode = ASEARCH;
-
- myPB.csParam[0] = 0;
- myPB.csParam[1] = AMSFADDR;
- myPB.csParam[2] = 0; /* must be in BCD */
- myPB.csParam[3] = (char) minute; /* must be in BCD */
- myPB.csParam[4] = (char) second; /* must be in BCD */
- myPB.csParam[5] = (char) block; /* must be in BCD */
- myPB.csParam[6] = 0;
- myPB.csParam[7] = flag;
- myPB.csParam[8] = 0;
- myPB.csParam[9] = playMode;
- return (PBControl(&myPB, false));
- }
-
-
- /* C routines for HyperCard callbacks */
- #include <XCmdGlue.inc.c>
-